package com.test.first;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class ConfigActivity extends AppCompatActivity {

    private static final String TAG = "ConfigActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config);


        Intent intent = getIntent();
        float dollar2 = intent.getFloatExtra("dollar_key",0.0f);
        float euro2 = intent.getFloatExtra("euro_key",0.0f);
        float won2 = intent.getFloatExtra("won_key",0.0f);


        EditText set1 = findViewById(R.id.set_dollar);
        set1.setHint(""+dollar2);

        EditText set2 = findViewById(R.id.set_euro);
        set2.setHint(""+euro2);

        EditText set3 = findViewById(R.id.set_won);
        set3.setHint(""+won2);


        Log.i(TAG,"onCreate: dollar2=" + dollar2);
        Log.i(TAG,"onCreate: euro2=" + euro2);
        Log.i(TAG,"onCreate: won2=" + won2);



    }

    public void save(View v){
        try{
            EditText set1 = findViewById(R.id.set_dollar);
            String str_d = set1.getText().toString();
            Float rate_d = Float.parseFloat(str_d);

            EditText set2 = findViewById(R.id.set_euro);
            String str_e = set2.getText().toString();
            Float rate_e = Float.parseFloat(str_e);

            EditText set3 = findViewById(R.id.set_won);
            String str_f = set3.getText().toString();
            Float rate_f =Float.parseFloat(str_f);


            Intent intent = getIntent();
            Bundle bdl = new Bundle();
            bdl.putFloat("key_dollar",rate_d);
            bdl.putFloat("key_euro",rate_e);
            bdl.putFloat("key_won",rate_f);
            intent.putExtras(bdl);

            setResult(2,intent);
            finish();

        }

        catch (Exception g){
            Toast.makeText(this,"请输入数字",Toast.LENGTH_SHORT).show();
        }

    }


}